Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
	''' <summary>
	''' Strongly-typed collection for the Games class.
	''' </summary>
	<Serializable> _
	Public Partial Class GamesCollection 
	Inherits ActiveList(Of Games, GamesCollection)
	    Public Sub New()
		End Sub
	End Class
	''' <summary>
	''' This is an ActiveRecord class which wraps the Games table.
	''' </summary>
	<Serializable> _
	Public Partial Class Games 
	Inherits ActiveRecord(Of Games)
		#Region ".ctors and Default Settings"
		
		Public Sub New()
			SetSQLProps()
			InitSetDefaults()
			MarkNew()
		End Sub
		
		Public Sub New(ByVal useDatabaseDefaults As Boolean)
			SetSQLProps()
			If useDatabaseDefaults = True Then
				ForceDefaults()
			End If
			MarkNew()
		End Sub
		Public Sub New(ByVal keyID As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByKey(keyID)
		End Sub
		Public Sub New(ByVal columnName As String, ByVal columnValue As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByParam(columnName,columnValue)
		End Sub
		Private Sub InitSetDefaults()
			SetDefaults()
		End Sub
		
		Protected Shared Sub SetSQLProps()
			GetTableSchema()
		End Sub
		#End Region
		
		#Region "Schema and Query Accessor"
		
		Public Shared ReadOnly Property Schema() As TableSchema.Table
			Get
				If BaseSchema Is Nothing Then
					SetSQLProps()
				End If
				Return BaseSchema
			End Get
		End Property
		Private Shared Sub GetTableSchema()
			If (Not IsSchemaInitialized) Then
				'Schema declaration
				Dim schema As TableSchema.Table = New TableSchema.Table("Games", TableType.Table, DataService.GetInstance("ClubStarterKitData"))
				schema.Columns = New TableSchema.TableColumnCollection()
				schema.SchemaName = "dbo"
				'columns
				
                
                Dim colvarId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarId.ColumnName = "id"
                colvarId.DataType = DbType.Int32
                colvarId.MaxLength = 0
                colvarId.AutoIncrement = true
                colvarId.IsNullable = false
                colvarId.IsPrimaryKey = true
                colvarId.IsForeignKey = false
                colvarId.IsReadOnly = false
                
                
                schema.Columns.Add(colvarId)
                
                Dim colvarTeam1id As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarTeam1id.ColumnName = "team1id"
                colvarTeam1id.DataType = DbType.Int32
                colvarTeam1id.MaxLength = 0
                colvarTeam1id.AutoIncrement = false
                colvarTeam1id.IsNullable = false
                colvarTeam1id.IsPrimaryKey = false
                colvarTeam1id.IsForeignKey = true
                colvarTeam1id.IsReadOnly = false
                
                
				colvarTeam1id.ForeignKeyTableName = "Teams"
                
                schema.Columns.Add(colvarTeam1id)
                
                Dim colvarTeam2id As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarTeam2id.ColumnName = "team2id"
                colvarTeam2id.DataType = DbType.Int32
                colvarTeam2id.MaxLength = 0
                colvarTeam2id.AutoIncrement = false
                colvarTeam2id.IsNullable = false
                colvarTeam2id.IsPrimaryKey = false
                colvarTeam2id.IsForeignKey = true
                colvarTeam2id.IsReadOnly = false
                
                
				colvarTeam2id.ForeignKeyTableName = "Teams"
                
                schema.Columns.Add(colvarTeam2id)
                
                Dim colvarDte As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarDte.ColumnName = "Dte"
                colvarDte.DataType = DbType.DateTime
                colvarDte.MaxLength = 0
                colvarDte.AutoIncrement = false
                colvarDte.IsNullable = false
                colvarDte.IsPrimaryKey = false
                colvarDte.IsForeignKey = false
                colvarDte.IsReadOnly = false
                
                
                schema.Columns.Add(colvarDte)
                
                Dim colvarTeam1score As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarTeam1score.ColumnName = "team1score"
                colvarTeam1score.DataType = DbType.String
                colvarTeam1score.MaxLength = 50
                colvarTeam1score.AutoIncrement = false
                colvarTeam1score.IsNullable = false
                colvarTeam1score.IsPrimaryKey = false
                colvarTeam1score.IsForeignKey = false
                colvarTeam1score.IsReadOnly = false
                
                
                schema.Columns.Add(colvarTeam1score)
                
                Dim colvarTeam2score As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarTeam2score.ColumnName = "team2score"
                colvarTeam2score.DataType = DbType.String
                colvarTeam2score.MaxLength = 50
                colvarTeam2score.AutoIncrement = false
                colvarTeam2score.IsNullable = false
                colvarTeam2score.IsPrimaryKey = false
                colvarTeam2score.IsForeignKey = false
                colvarTeam2score.IsReadOnly = false
                
                
                schema.Columns.Add(colvarTeam2score)
                
                Dim colvarNewsID As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarNewsID.ColumnName = "newsID"
                colvarNewsID.DataType = DbType.Int32
                colvarNewsID.MaxLength = 0
                colvarNewsID.AutoIncrement = false
                colvarNewsID.IsNullable = true
                colvarNewsID.IsPrimaryKey = false
                colvarNewsID.IsForeignKey = false
                colvarNewsID.IsReadOnly = false
                
                
                schema.Columns.Add(colvarNewsID)
                
                Dim colvarIsComplete As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarIsComplete.ColumnName = "IsComplete"
                colvarIsComplete.DataType = DbType.Boolean
                colvarIsComplete.MaxLength = 0
                colvarIsComplete.AutoIncrement = false
                colvarIsComplete.IsNullable = false
                colvarIsComplete.IsPrimaryKey = false
                colvarIsComplete.IsForeignKey = false
                colvarIsComplete.IsReadOnly = false
                
                
                schema.Columns.Add(colvarIsComplete)
                
				BaseSchema = schema
				
				'add this schema to the provider
                'so we can query it later
                DataService.Providers("ClubStarterKitData").AddSchema("Games",schema)
			End If
		End Sub
		Public Shared Function CreateQuery() As Query
			Return New Query(Schema)
		End Function
		
		#End Region
		
		#Region "Props"
	
          
        <XmlAttribute("Id")> _
        Public Property Id As Integer 
			Get
				Return GetColumnValue(Of Integer)("id")
			End Get
		    
			Set
				SetColumnValue("id", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Team1id")> _
        Public Property Team1id As Integer 
			Get
				Return GetColumnValue(Of Integer)("team1id")
			End Get
		    
			Set
				SetColumnValue("team1id", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Team2id")> _
        Public Property Team2id As Integer 
			Get
				Return GetColumnValue(Of Integer)("team2id")
			End Get
		    
			Set
				SetColumnValue("team2id", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Dte")> _
        Public Property Dte As DateTime 
			Get
				Return GetColumnValue(Of DateTime)("Dte")
			End Get
		    
			Set
				SetColumnValue("Dte", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Team1score")> _
        Public Property Team1score As String 
			Get
				Return GetColumnValue(Of String)("team1score")
			End Get
		    
			Set
				SetColumnValue("team1score", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Team2score")> _
        Public Property Team2score As String 
			Get
				Return GetColumnValue(Of String)("team2score")
			End Get
		    
			Set
				SetColumnValue("team2score", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("NewsID")> _
        Public Property NewsID As Nullable(Of Integer) 
			Get
				Return GetColumnValue(Of Nullable(Of Integer))("newsID")
			End Get
		    
			Set
				SetColumnValue("newsID", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("IsComplete")> _
        Public Property IsComplete As Boolean 
			Get
				Return GetColumnValue(Of Boolean)("IsComplete")
			End Get
		    
			Set
				SetColumnValue("IsComplete", Value)
			End Set
		End Property
		
		
		
		
		#End Region
		
		
			    
	    
	    #Region "PrimaryKey Methods"
	    
			Public Function PlayersInStatsRecords() As Data.PlayersInStatsCollection 
	
				Return New Data.PlayersInStatsCollection().Where(PlayersInStats.Columns.Gameid, Id).Load()
	
			End Function
			
		#End Region
		
		
		
		
		
		
	    
	    #Region "ForeignKey Methods"
	    
		''' <summary>
		''' Returns a Teams ActiveRecord object related to this Games
		''' </summary>
		Public Property Teams() As Data.Teams
			Get
				Return Data.Teams.FetchByID(Me.Team1id)
			End Get
			Set
				SetColumnValue("team1id", Value.Id)
			End Set
		End Property
	    
		''' <summary>
		''' Returns a Teams ActiveRecord object related to this Games
		''' </summary>
		Public Property TeamsToTeam2id() As Data.Teams
			Get
				Return Data.Teams.FetchByID(Me.Team2id)
			End Get
			Set
				SetColumnValue("team2id", Value.Id)
			End Set
		End Property
	    
	    #End Region
	    
		
	    
	    'no ManyToMany tables defined (0)
	    
		
		#Region "ObjectDataSource support"
		
		''' <summary>
		''' Inserts a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Insert(ByVal varTeam1id As Integer,ByVal varTeam2id As Integer,ByVal varDte As DateTime,ByVal varTeam1score As String,ByVal varTeam2score As String,ByVal varNewsID As Nullable(Of Integer),ByVal varIsComplete As Boolean)
			Dim item As Games = New Games()
			
            item.Team1id = varTeam1id
            
            item.Team2id = varTeam2id
            
            item.Dte = varDte
            
            item.Team1score = varTeam1score
            
            item.Team2score = varTeam2score
            
            item.NewsID = varNewsID
            
            item.IsComplete = varIsComplete
            
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		''' <summary>
		''' Updates a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Update(ByVal varId As Integer,ByVal varTeam1id As Integer,ByVal varTeam2id As Integer,ByVal varDte As DateTime,ByVal varTeam1score As String,ByVal varTeam2score As String,ByVal varNewsID As Nullable(Of Integer),ByVal varIsComplete As Boolean)
			Dim item As Games = New Games()
		    
                item.Id = varId
				
                item.Team1id = varTeam1id
				
                item.Team2id = varTeam2id
				
                item.Dte = varDte
				
                item.Team1score = varTeam1score
				
                item.Team2score = varTeam2score
				
                item.NewsID = varNewsID
				
                item.IsComplete = varIsComplete
				
			item.IsNew = False
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		#End Region
		#Region "Columns Struct"
		Public Structure Columns
			Dim x as Integer
			
            Public Shared Id As String = "id"
            
            Public Shared Team1id As String = "team1id"
            
            Public Shared Team2id As String = "team2id"
            
            Public Shared Dte As String = "Dte"
            
            Public Shared Team1score As String = "team1score"
            
            Public Shared Team2score As String = "team2score"
            
            Public Shared NewsID As String = "newsID"
            
            Public Shared IsComplete As String = "IsComplete"
            
		End Structure
		#End Region
	End Class
End Namespace
